<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>18.数组排序使用技巧</title>
</head>

<body>
  <script>
    let arr = [1, 5, 7, 3, 4];
    arr = arr.sort(function (a, b) {
      //  a-b 负数 从小到达 ，b-a 正数 从大到小
      return a - b;
    });
    console.table(arr);

    let cart = [
      { name: 'iphone', price: 12000 },
      { name: 'imac', price: 18000 },
      { name: 'ipad', price: 3200 }
    ]
    cart = cart.sort(function (a, b) {
      return a.price - b.price;
    });
    console.log(cart);
  </script>
</body>

</html>